package com.ruoyi.common.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtilTool {

    public static void main(String[] args) {
        System.out.println(numberSupplement("2020-1".split("-")[1],4));
    }




  public static String  numberSupplement(String number, int num){
          int lenNum=number.length();
          if (num<=lenNum){
              return  number;
          }else{
              StringBuffer stringBuffer=new StringBuffer();
              for (int i=1;i<=num-lenNum;i++){
                  stringBuffer.append("0");
              }
              stringBuffer.append(number);
              return  stringBuffer.toString();
          }
    }

    public static boolean isInteger(String str) {
        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
        return pattern.matcher(str).matches();
    }

    public  String changeNumType(String pInStr) {
        char[] arr = pInStr.toCharArray();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < arr.length; i++) {
            if ((arr[i] - '0' >= 0) && (arr[i] - '0' <= 9)) { // 判断为数字
                sb.append("<span style=\"font-size:21px;font-family:&#39;Times New Roman&#39;,&#39;serif&#39;;color:red\">" + arr[i] + "</span>");//两边都加上*
            } else sb.append(arr[i]);

        }
        return sb.toString().replace("</span><span style=\\\"font-size:21px;font-family:&#39;Times New Roman&#39;,&#39;serif&#39;;color:red\\\">","");//两个数字中间有** 替换掉
    }


    // 判断一个字符串是否含有数字
    public static boolean HasDigit(String content) {
        boolean flag = false;
        Pattern p = Pattern.compile(".*\\d+.*");
        Matcher m = p.matcher(content);
        if (m.matches()) {
            flag = true;
        }
        return flag;
    }
    // 判断一个字符串是否含有字母
    public static boolean judgeContainsStr(String str) {
        String regex=".*[a-zA-Z]+.*";
        Matcher m=Pattern.compile(regex).matcher(str);
        return m.matches();
    }

    // 判断一个字符串是否是字母
    public static boolean is_alpha(String str) {
        if(str==null) return false;
        return str.matches("[a-zA-Z]+");
    }

    //判断是否为空
    public static boolean isNull(String str) {

        return str == null || str.length() == 0;
    }
}
